﻿Public Partial Class ProductPopup
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (IsPostBack) Then
            ViewState("index") = ""
            If Not Session("PORT_PRODUCT") Is Nothing Then
                ViewState("Port") = Session("PORT_PRODUCT")
                AutoCompleteExtender3.ContextKey = ViewState("Port")
                Dim ds As DataTable
                ' ds = clsGet.Get_ProductGroupMaster("", "A")
                'If (ds.Rows.Count > 0) Then
                '    With ddlGroup
                '        .ClearSelection()
                '        .DataTextField = "Group_name"
                '        .DataValueField = "Group_no"
                '        .DataSource = ds
                '        .DataBind()
                '        .Items.Insert(0, "<--กรุณาเลือกกลุ่มสินค้า-->")
                '        .Items(0).Value = "0"
                '    End With
                'End If

                ds = clsGet.Get_Buyer_Seller("", "A")
                If (ds.Rows.Count > 0) Then
                    With ddlBuyerDisch
                        .ClearSelection()
                        .DataTextField = "BS_name"
                        .DataValueField = "BS_no"
                        .DataSource = ds
                        .DataBind()
                        .Items.Insert(0, "<--SELECT BUYER-->")
                        .Items(0).Value = "0"
                    End With
                    With ddlSellerLoad
                        .ClearSelection()
                        .DataTextField = "BS_name"
                        .DataValueField = "BS_no"
                        .DataSource = ds
                        .DataBind()
                        .Items.Insert(0, "<--SELECT SELLER-->")
                        .Items(0).Value = "0"
                    End With
                End If

                If Not (Session("IndexProduct") Is Nothing) Then
                    Dim dt As DataTable = Session("Product_popup")
                    Dim index As Integer = CInt(Session("IndexProduct"))
                    ViewState("index") = index
                    If Not (ddlProduct.Items.FindByValue(dt.Rows(index).Item("Product_Event")) Is Nothing) Then
                        ddlProduct.SelectedValue = dt.Rows(index).Item("Product_Event")
                    End If
                    txtProductName.Text = dt.Rows(index).Item("Product_name")
                    txtProduct.Text = dt.Rows(index).Item("Product_Amount")
                    txtDescription.Text = dt.Rows(index).Item("Product_Description")
                    If Not (ddlUnit.Items.FindByValue(dt.Rows(index).Item("Product_Unit")) Is Nothing) Then
                        ddlUnit.SelectedValue = dt.Rows(index).Item("Product_Unit")
                    End If
                    'If Not (ddlGroup.Items.FindByValue(dt.Rows(index).Item("Group_no")) Is Nothing) Then
                    '    ddlGroup.SelectedValue = dt.Rows(index).Item("Group_no")
                    'End If
                    If (ViewState("Port") = "B") Then
                        'Bulk

                        If (dt.Rows(index).Item("Product_Event") = "L") Or (dt.Rows(index).Item("Product_Event") = "R") Then
                            txtBulkDestination.Text = dt.Rows(index).Item("DestinationShow")
                            If Not (dt.Rows(index).Item("Owner_Product_no") & "" = "") Then
                                txtOwner_Product.Text = dt.Rows(index).Item("Owner_Product_no") & "-" & dt.Rows(index).Item("Owner_Product_name")
                                txtOwner_Product.Enabled = False
                            Else
                                txtOwner_Product.Enabled = True
                            End If
                            txtBuyerBulkLoad.Text = dt.Rows(index).Item("Product_BUYER_name")
                            rowLoadB.Visible = True
                            rowDischB.Visible = False
                        Else
                            'Disch
                            rowDischB.Visible = True
                            rowLoadB.Visible = False
                            txtBulkDestination.Text = dt.Rows(index).Item("DestinationShow")
                            If Not (dt.Rows(index).Item("Owner_Product_no") & "" = "") Then
                                txtOwner_ProductDisch.Text = dt.Rows(index).Item("Owner_Product_no") & "-" & dt.Rows(index).Item("Owner_Product_name")
                                txtOwner_ProductDisch.Enabled = False
                            Else
                                txtOwner_ProductDisch.Enabled = True
                            End If
                            txtSellerBulkDisch.Text = dt.Rows(index).Item("Product_SELLER_name")
                            rowLoadB.Visible = False
                            rowDischB.Visible = True
                        End If


                    Else
                        'Liquid
                        If (dt.Rows(index).Item("Product_Event") = "L") Or (dt.Rows(index).Item("Product_Event") = "R") Then
                            txtBuyerLoad.Text = dt.Rows(index).Item("Product_BUYER_name")
                            If Not (ddlSellerLoad.Items.FindByValue(dt.Rows(index).Item("Product_SELLER_no")) Is Nothing) Then
                                ddlSellerLoad.SelectedValue = dt.Rows(index).Item("Product_SELLER_no")
                            End If
                            txtLoadDestination.Text = dt.Rows(index).Item("DestinationShow")
                            rowLoadL.Visible = True
                            rowDischL.Visible = False
                        Else
                            rowDischL.Visible = True
                            rowLoadL.Visible = False
                            'Disch
                            If Not (ddlBuyerDisch.Items.FindByValue(dt.Rows(index).Item("Product_BUYER_no")) Is Nothing) Then
                                ddlBuyerDisch.SelectedValue = dt.Rows(index).Item("Product_BUYER_no")
                            End If
                            txtSellerDisch.Text = dt.Rows(index).Item("Product_SELLER_name")
                            txtDischDestination.Text = dt.Rows(index).Item("DestinationShow")
                        End If
                    End If
                End If
                If (ViewState("Port") = "B") Then
                    rowBulk.Visible = True
                    rowLiquid.Visible = False
                Else
                    rowBulk.Visible = False
                    rowLiquid.Visible = True
                End If
            End If
        End If
    End Sub

    Private Sub ddlProduct_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProduct.SelectedIndexChanged
        If (ViewState("Port") = "B") Then
            If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                rowLoadB.Visible = True
                rowDischB.Visible = False
                lbBulkDestination.Text = "DISCHARGING PORT"
            Else
                rowDischB.Visible = True
                rowLoadB.Visible = False
                lbBulkDestination.Text = "LOADING PORT"
            End If
        Else
            If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                rowLoadL.Visible = True
                rowDischL.Visible = False
            Else
                rowDischL.Visible = True
                rowLoadL.Visible = False
            End If
        End If

    End Sub

    'Private Sub ddlGroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlGroup.SelectedIndexChanged
    '    AutoCompleteExtender3.ContextKey = ddlGroup.SelectedValue
    'End Sub

    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Session("PORT_PRODUCT") = Nothing
        Session("IndexProduct") = Nothing
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModal('D');", True)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Session("PORT_PRODUCT") = Nothing
        Session("IndexProduct") = Nothing
        If addProduct() Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModal('P');", True)
        End If


    End Sub

    Private Function addProduct() As Boolean
        If ((txtProduct.Text.Trim() = "") Or (txtProductName.Text.Trim() = "")) Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการระบุข้อมูลสินค้า !!');", True)
            Return False
        End If
        Dim product As DataTable = clsGet.Get_Product_no(txtProductName.Text)
        'If product.Rows.Count <> 1 Then
        '    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ไม่พบข้อมูลสินค้า !!');", True)
        '    Return False
        'End If
        If (ViewState("Port") = "L") Then
            If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                'load
                If (txtBuyerLoad.Text.Trim = "") Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการระบุ BUYER !!');", True)
                    Return False
                End If
                If (ddlSellerLoad.SelectedValue = "0") Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการเลือก SELLER !!');", True)
                    Return False
                End If
            Else
                'disch
                If (ddlBuyerDisch.SelectedValue = "0") Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการเลือก BUYER !!');", True)
                    Return False
                End If
                If (txtSellerDisch.Text.Trim = "") Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการระบุ SELLER !!');", True)
                    Return False
                End If
            End If
        Else
            If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                'Load
                If (txtOwner_Product.Text.Trim <> "") Then
                    If ((clsGet.Get_Customer(txtOwner_Product.Text.Trim().Split("-")(0))).Rows.Count < 1) Then
                        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ไม่พบข้อมูลเจ้าของสินค้า !!');", True)
                        Return False
                    End If
                End If
            Else
                'Disch
                If (txtOwner_ProductDisch.Text.Trim <> "") Then
                    If ((clsGet.Get_Customer(txtOwner_ProductDisch.Text.Trim().Split("-")(0))).Rows.Count < 1) Then
                        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('ไม่พบข้อมูลเจ้าของสินค้า !!');", True)
                        Return False
                    End If
                End If
            End If

        End If
        Dim ds As DataTable = Session("Product_popup")
        'เช็ครายการสินค้าซ้ำ
        'If (product.Rows.Count > 0) Then

        '    If (ViewState("index") & "" = "") Then
        '        For Each dr As DataRow In ds.Rows
        '            If (dr.Item("Product_no") = product.Rows(0).Item("Product_no")) Then
        '                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('สินค้าได้ถูกเพิ่มก่อนหน้านี้แล้ว !!');", True)
        '                Return False
        '            End If
        '        Next
        '    End If
        'End If


        Dim Product_no As String = ""
        Dim Group_no As String = ""
        Dim Group_name As String = ""
        If (product.Rows.Count = 0) Then
            Product_no = "0000000000"
            Group_no = "0000000000"
            Group_name = "-"
        Else
            Product_no = product.Rows(0).Item("Product_no")
            Group_no = product.Rows(0).Item("Group_no")
            Group_name = product.Rows(0).Item("Group_name")
        End If
        Dim chk As Boolean = False
        For Each dk As DataRow In ds.Rows
            If (dk.Item("Product_no") = Product_no) Then
                If (dk.Item("Product_Amount") = txtProduct.Text) Then

                    If (ViewState("Port") = "L") Then
                        If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                            If (dk.Item("Product_BUYER_name") = txtBuyerLoad.Text) Then
                                If (dk.Item("Product_SELLER_name") = ddlSellerLoad.SelectedItem.Text) Then
                                    If (dk.Item("LoadDestination") = txtLoadDestination.Text) Then
                                        chk = True
                                    End If
                                End If
                            End If
                        Else
                            If (dk.Item("Product_BUYER_name") = ddlBuyerDisch.SelectedItem.Text) Then
                                If (dk.Item("Product_SELLER_name") = txtSellerDisch.Text) Then
                                    If (dk.Item("LoadDestination") = txtLoadDestination.Text) Then
                                        chk = True
                                    End If
                                End If
                            End If
                        End If
                    Else
                        If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                            If (dk.Item("Product_BUYER_name") = txtBuyerBulkLoad.Text) Then
                                If (dk.Item("LoadDestination") = txtBulkDestination.Text) Then
                                    chk = True
                                End If
                            End If
                        Else
                            If (dk.Item("Product_SELLER_name") = txtSellerBulkDisch.Text) Then
                                If (dk.Item("LoadDestination") = txtBulkDestination.Text) Then
                                    chk = True
                                End If
                            End If
                        End If
                    End If


                End If
            End If
        Next
        If (chk) Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('สินค้ามีรายละเอียดที่เหมือนกันทุกประการกรุณาทำการรวมน้ำหนัก !!');", True)
            Return False
        End If
        If (ds.Rows(0).Item("Product_name") & "" = "") Then
            ds.Rows(0).Item("Product_no") = Product_no
            ds.Rows(0).Item("Product_name") = txtProductName.Text
            ds.Rows(0).Item("Product_Amount") = txtProduct.Text
            ds.Rows(0).Item("Product_Event") = ddlProduct.SelectedValue
            ds.Rows(0).Item("Product_Description") = txtDescription.Text
            ds.Rows(0).Item("Product_Unit") = ddlUnit.SelectedValue
            ds.Rows(0).Item("Group_no") = Group_no
            ds.Rows(0).Item("Group_name") = Group_name
            If (ViewState("Port") = "L") Then
                If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                    'Load
                    ds.Rows(0).Item("Product_BUYER_no") = ""
                    ds.Rows(0).Item("Product_BUYER_name") = txtBuyerLoad.Text
                    ds.Rows(0).Item("Product_SELLER_no") = ddlSellerLoad.SelectedValue
                    ds.Rows(0).Item("Product_SELLER_name") = ddlSellerLoad.SelectedItem.Text
                    ds.Rows(0).Item("LoadDestination") = txtLoadDestination.Text
                    ds.Rows(0).Item("DischDestination") = ""
                    ds.Rows(0).Item("DestinationShow") = txtLoadDestination.Text
                Else
                    'Disch
                    ds.Rows(0).Item("Product_BUYER_no") = ddlBuyerDisch.SelectedValue
                    ds.Rows(0).Item("Product_BUYER_name") = ddlBuyerDisch.SelectedItem.Text
                    ds.Rows(0).Item("Product_SELLER_no") = ""
                    ds.Rows(0).Item("Product_SELLER_name") = txtSellerDisch.Text
                    ds.Rows(0).Item("DischDestination") = txtDischDestination.Text
                    ds.Rows(0).Item("LoadDestination") = ""
                    ds.Rows(0).Item("DestinationShow") = txtDischDestination.Text
                End If
                ds.Rows(0).Item("Owner_Product_no") = ""
                ds.Rows(0).Item("Owner_Product_name") = ""
            Else
                'Bulk
                If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                    'Load
                    ds.Rows(0).Item("Product_BUYER_no") = ""
                    ds.Rows(0).Item("Product_BUYER_name") = txtBuyerBulkLoad.Text
                    ds.Rows(0).Item("Product_SELLER_no") = ""
                    ds.Rows(0).Item("Product_SELLER_name") = ""
                    ds.Rows(0).Item("LoadDestination") = txtBulkDestination.Text
                    ds.Rows(0).Item("DischDestination") = ""
                    ds.Rows(0).Item("DestinationShow") = txtBulkDestination.Text
                    If (txtOwner_Product.Text.Trim = "") Then
                        ds.Rows(0).Item("Owner_Product_no") = ""
                        ds.Rows(0).Item("Owner_Product_name") = ""
                    Else
                        ds.Rows(0).Item("Owner_Product_no") = txtOwner_Product.Text.Split("-")(0)
                        ds.Rows(0).Item("Owner_Product_name") = txtOwner_Product.Text.Split("-")(1)
                    End If
                Else
                    'Disch
                    ds.Rows(0).Item("Product_BUYER_no") = ""
                    ds.Rows(0).Item("Product_BUYER_name") = ""
                    ds.Rows(0).Item("Product_SELLER_no") = ""
                    ds.Rows(0).Item("Product_SELLER_name") = txtSellerBulkDisch.Text
                    ds.Rows(0).Item("DischDestination") = txtBulkDestination.Text
                    ds.Rows(0).Item("LoadDestination") = ""
                    ds.Rows(0).Item("DestinationShow") = txtBulkDestination.Text
                    If (txtOwner_ProductDisch.Text.Trim = "") Then
                        ds.Rows(0).Item("Owner_Product_no") = ""
                        ds.Rows(0).Item("Owner_Product_name") = ""
                    Else
                        ds.Rows(0).Item("Owner_Product_no") = txtOwner_ProductDisch.Text.Split("-")(0)
                        ds.Rows(0).Item("Owner_Product_name") = txtOwner_ProductDisch.Text.Split("-")(1)
                    End If
                End If

            End If

            ds.AcceptChanges()
        ElseIf (ViewState("index") & "" <> "") Then
            Dim index As Integer = CInt(ViewState("index"))
            ds.Rows(index).Item("Product_no") = Product_no
            ds.Rows(index).Item("Product_name") = txtProductName.Text
            ds.Rows(index).Item("Product_Amount") = txtProduct.Text
            ds.Rows(index).Item("Product_Event") = ddlProduct.SelectedValue
            ds.Rows(index).Item("Product_Description") = txtDescription.Text
            ds.Rows(index).Item("Product_Unit") = ddlUnit.SelectedValue
            ds.Rows(index).Item("Group_no") = Group_no
            ds.Rows(index).Item("Group_name") = Group_name
            If (ViewState("Port") = "L") Then
                If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                    'Load
                    ds.Rows(index).Item("Product_BUYER_no") = ""
                    ds.Rows(index).Item("Product_BUYER_name") = txtBuyerLoad.Text
                    ds.Rows(index).Item("Product_SELLER_no") = ddlSellerLoad.SelectedValue
                    ds.Rows(index).Item("Product_SELLER_name") = ddlSellerLoad.SelectedItem.Text
                    ds.Rows(index).Item("LoadDestination") = txtLoadDestination.Text
                    ds.Rows(index).Item("DischDestination") = ""
                    ds.Rows(index).Item("DestinationShow") = txtLoadDestination.Text
                Else
                    'Disch
                    ds.Rows(index).Item("Product_BUYER_no") = ddlBuyerDisch.SelectedValue
                    ds.Rows(index).Item("Product_BUYER_name") = ddlBuyerDisch.SelectedItem.Text
                    ds.Rows(index).Item("Product_SELLER_no") = ""
                    ds.Rows(index).Item("Product_SELLER_name") = txtSellerDisch.Text
                    ds.Rows(index).Item("DischDestination") = txtDischDestination.Text
                    ds.Rows(index).Item("LoadDestination") = ""
                    ds.Rows(index).Item("DestinationShow") = txtDischDestination.Text
                End If
                ds.Rows(index).Item("Owner_Product_no") = ""
                ds.Rows(index).Item("Owner_Product_name") = ""
            Else
                'Bulk
                If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                    'Load
                    ds.Rows(index).Item("Product_BUYER_no") = ""
                    ds.Rows(index).Item("Product_BUYER_name") = txtBuyerBulkLoad.Text
                    ds.Rows(index).Item("Product_SELLER_no") = ""
                    ds.Rows(index).Item("Product_SELLER_name") = ""
                    ds.Rows(index).Item("LoadDestination") = txtBulkDestination.Text
                    ds.Rows(index).Item("DischDestination") = ""
                    ds.Rows(index).Item("DestinationShow") = txtBulkDestination.Text
                    If (txtOwner_Product.Text.Trim = "") Then
                        ds.Rows(index).Item("Owner_Product_no") = ""
                        ds.Rows(index).Item("Owner_Product_name") = ""
                    Else
                        ds.Rows(index).Item("Owner_Product_no") = txtOwner_Product.Text.Split("-")(0)
                        ds.Rows(index).Item("Owner_Product_name") = txtOwner_Product.Text.Split("-")(1)
                    End If
                Else
                    'Disch
                    ds.Rows(index).Item("Product_BUYER_no") = ""
                    ds.Rows(index).Item("Product_BUYER_name") = ""
                    ds.Rows(index).Item("Product_SELLER_no") = ""
                    ds.Rows(index).Item("Product_SELLER_name") = txtSellerBulkDisch.Text
                    ds.Rows(index).Item("DischDestination") = txtBulkDestination.Text
                    ds.Rows(index).Item("LoadDestination") = ""
                    ds.Rows(index).Item("DestinationShow") = txtBulkDestination.Text
                    If (txtOwner_ProductDisch.Text.Trim = "") Then
                        ds.Rows(index).Item("Owner_Product_no") = ""
                        ds.Rows(index).Item("Owner_Product_name") = ""
                    Else
                        ds.Rows(index).Item("Owner_Product_no") = txtOwner_ProductDisch.Text.Split("-")(0)
                        ds.Rows(index).Item("Owner_Product_name") = txtOwner_ProductDisch.Text.Split("-")(1)
                    End If
                End If

            End If

            ds.AcceptChanges()
        Else
            Dim dr As DataRow = ds.NewRow()
            dr.Item("Product_no") = Product_no
            dr.Item("Product_name") = txtProductName.Text
            dr.Item("Product_Amount") = txtProduct.Text
            dr.Item("Product_Event") = ddlProduct.SelectedValue
            dr.Item("Product_Description") = txtDescription.Text
            dr.Item("Product_Unit") = ddlUnit.SelectedValue
            dr.Item("Group_no") = Group_no
            dr.Item("Group_name") = Group_name
            If (ViewState("Port") = "L") Then
                If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                    'Load
                    dr.Item("Product_BUYER_no") = ""
                    dr.Item("Product_BUYER_name") = txtBuyerLoad.Text
                    dr.Item("Product_SELLER_no") = ddlSellerLoad.SelectedValue
                    dr.Item("Product_SELLER_name") = ddlSellerLoad.SelectedItem.Text
                    dr.Item("LoadDestination") = txtLoadDestination.Text
                    dr.Item("DischDestination") = ""
                    dr.Item("DestinationShow") = txtLoadDestination.Text
                Else
                    'Disch
                    dr.Item("Product_BUYER_no") = ddlBuyerDisch.SelectedValue
                    dr.Item("Product_BUYER_name") = ddlBuyerDisch.SelectedItem.Text
                    dr.Item("Product_SELLER_no") = ""
                    dr.Item("Product_SELLER_name") = txtSellerDisch.Text
                    dr.Item("DischDestination") = txtDischDestination.Text
                    dr.Item("LoadDestination") = ""
                    dr.Item("DestinationShow") = txtDischDestination.Text
                End If
                dr.Item("Owner_Product_no") = ""
                dr.Item("Owner_Product_name") = ""
            Else
                'Bulk
                If (ddlProduct.SelectedValue = "L") Or (ddlProduct.SelectedValue = "R") Then
                    'Load
                    dr.Item("Product_BUYER_no") = ""
                    dr.Item("Product_BUYER_name") = txtBuyerBulkLoad.Text
                    dr.Item("Product_SELLER_no") = ""
                    dr.Item("Product_SELLER_name") = ""
                    dr.Item("LoadDestination") = txtBulkDestination.Text
                    dr.Item("DischDestination") = ""
                    dr.Item("DestinationShow") = txtBulkDestination.Text

                    If (txtOwner_Product.Text.Trim() = "") Then
                        dr.Item("Owner_Product_no") = ""
                        dr.Item("Owner_Product_name") = ""
                    Else
                        dr.Item("Owner_Product_no") = txtOwner_Product.Text.Split("-")(0)
                        dr.Item("Owner_Product_name") = txtOwner_Product.Text.Split("-")(1)
                    End If
                Else
                    'Disch
                    dr.Item("Product_BUYER_no") = ""
                    dr.Item("Product_BUYER_name") = ""
                    dr.Item("Product_SELLER_no") = ""
                    dr.Item("Product_SELLER_name") = txtSellerBulkDisch.Text
                    dr.Item("DischDestination") = txtBulkDestination.Text
                    dr.Item("LoadDestination") = ""
                    dr.Item("DestinationShow") = txtBulkDestination.Text

                    If (txtOwner_ProductDisch.Text.Trim() = "") Then
                        dr.Item("Owner_Product_no") = ""
                        dr.Item("Owner_Product_name") = ""
                    Else
                        dr.Item("Owner_Product_no") = txtOwner_ProductDisch.Text.Split("-")(0)
                        dr.Item("Owner_Product_name") = txtOwner_ProductDisch.Text.Split("-")(1)
                    End If
                End If
            End If

            ds.Rows.Add(dr)
            ds.AcceptChanges()
        End If
        ddlProduct.ClearSelection()
        txtProduct.Text = String.Empty
        txtProductName.Text = String.Empty
        txtDescription.Text = String.Empty
        ddlUnit.ClearSelection()
        ddlBuyerDisch.ClearSelection()
        txtLoadDestination.Text = String.Empty
        txtDischDestination.Text = String.Empty
        ddlSellerLoad.ClearSelection()
        txtBuyerLoad.Text = String.Empty
        txtSellerDisch.Text = String.Empty
        If (ViewState("Port") = "L") Then
            rowDischL.Visible = False
            rowLoadL.Visible = True
        Else
            lbBulkDestination.Text = "LOADING PORT"
            txtBulkDestination.Text = String.Empty
            txtOwner_Product.Text = ""
        End If

        Session("Product_popup") = ds
        Return True
    End Function

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "")
        End If
    End Sub
End Class